package cn.easybuy.service;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.easybuy.biz.Categorybiz;
import cn.easybuy.biz.Impl.CategorybizImpl;
import cn.easybuy.entity.Category;

public class category extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		String parentId = request.getParameter("parentId");
		PrintWriter out = response.getWriter();
		Categorybiz ca = new CategorybizImpl();
		List<Category> list = ca.geterCategories(Integer.parseInt(parentId));
		int id;
		StringBuffer sBuffer = new StringBuffer();
		for (Category category : list) {
			id = category.getId();
			sBuffer.append("<div  class=\"zj_l_c\"><h2>" + category.getName()
					+ "</h2>");
			List<Category> list2 = ca.getsanCategories(id);
			for (Category category2 : list2) {
				sBuffer.append("<a href=\"servlet/ProductService?id="
						+ category2.getId() + "\">" + category2.getName()
						+ "</a>");
			}
			sBuffer.append("</div>");
		}
		out.print(sBuffer);
		out.flush();
		out.close();
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doGet(request, response);
	}

}
